package me.zhengjie.log.utils;

import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

import java.io.Serializable;
import java.util.List;

@Data
@NoArgsConstructor
@Accessors(chain = true)
public class Result<T> implements Serializable {

    private Integer code;

    private String message;

    private T data;

    private Integer needCheck;

    private String subCode;

    private Permission fieldPermission;

    public Result(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    public Result(Integer code, T data) {
        this.code = code;
        this.data = data;
    }

    public Result(Integer code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public static <T> Result<T> success() {
        return new Result<T>(200, "操作成功");
    }

    public static <T> Result<T> successmes() {
        return new Result<>(200, "操作成功");
    }

    public static <T> Result<T> fail(String message) {
        return new Result<>(-1, message);
    }
    public static <T> Result<T> fail(T data,Integer code) {
        return new Result<>(code, data);
    }

    public static <T> Result<T> success(T date) {
        return new Result<>(200, "操作成功", date);
    }

    public static <T> Result<T> error() {
        return new Result<T>(500, "操作失败");
    }

    public static <T> Result<T> error(String message) {
        return new Result<T>(500, message);
    }

    public static <T> Result<T> error(Integer code, String message) {
        return new Result<T>(code, message);
    }


    static class Permission {
        private String encoding;
        private List<String> noAccess;
        private List<String> readonly;
    }
}
